package com.homework.util;

import java.net.URISyntaxException;

public class PublicMethod {
	//获取一个存储地址的文件后缀,如.txt
	//如果没有文件后缀，返回""
	public static String getLastString(String address){
		//后缀前一个字符"."，的位置
		int fig = address.lastIndexOf(".");
		if(fig < 0){//没有后缀
			return "";
		}
		int lastLength = address.length()-fig;
		char[] last = new char[lastLength];		
		for(int i=0 ; i<lastLength ; i++){
			last[i] = address.charAt(fig+i);
		}
		String lastString = new String(last);
		return lastString;
	}
	
	//获取tomcat下工程的绝对路径
	public static String getAbsolutePath() throws URISyntaxException{
		String path = connDB.class.getResource("/").toURI().getPath();	
		String absolutePath = path.substring(1, path.indexOf("WEB-INF"));	
		return absolutePath;
	}
	
	public static String getEvaPath(){
		String path = "";
		path = "/data_homework/evaluation/";
		return path;
	}
	
	public static String getHomeworkPath(){
		String path = "";
		path = "/data_homework/homework/";
		return path;
	}
	
	public static String getVicPath(){
		String path = "";
		path =  "/data_homework/homework/";
		return path;
	}

	//获取文件名后缀
	//如从1.txt获得.txt
	public static String getSuffix(String filename){
		return filename.substring(filename.lastIndexOf("."));
	}
}
